/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lowagie.text.Cell;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.Barcode128;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.rtf.RtfWriter2;
import com.minierp.bean.QueryParameterBean;
import com.minierp.bean.QueryResult;
import com.minierp.bean.SetuBillBean;
import com.minierp.bean.SetuBillItemBean;
import com.minierp.bean.UserBean;
import com.minierp.bean.UserStatus;
import com.minierp.dao.BusinessBillItemDao;
import com.minierp.dao.CodeRuleDao;
import com.minierp.dao.IdGenerator;
import com.minierp.dao.MakeTypeDao;
import com.minierp.dao.QueryDao;
import com.minierp.dao.SerialNumberDao;
import com.minierp.dao.SetuBillDao;
import com.minierp.dao.SetuBillItemDao;
import com.minierp.dao.TallySetDao;
import com.minierp.err.NotAllowException;
import com.minierp.err.PermissionDennyException;
import com.minierp.helper.EncCommonHelper;
import com.minierp.helper.EncInterceptorHelper;
import com.minierp.helper.EncSetuBillMACtrHelper;
import com.minierp.helper.PageHelper;
import com.minierp.model.BusinessBill;
import com.minierp.model.BusinessBillItem;
import com.minierp.model.CodeRule;
import com.minierp.model.EnterpriseInfo;
import com.minierp.model.Establishment;
import com.minierp.model.MakeType;
import com.minierp.model.SetuBill;
import com.minierp.model.SetuBillItem;
import com.minierp.model.TallySet;
import com.minierp.service.SetuBillService;
import com.minierp.view.SetuBillListExcelView;
import com.minierp.view.SetuBillListForCompExcelView;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class SetuBillMACtr extends MultiActionController {
	private String dialogSuccessView;
	private String listForExamineView;
	private String infoForExamineView;
	private String listForUnExamineView;
	private String infoForUnExamineView;
	private String listForCancelView;
	private String infoForCancelView;
	private String listForCompView;
	private String listForUnCompView;
	private String searchResultView;
	private String printView;
	private BusinessBillItemDao businessBillItemDao;
	private SetuBillDao setuBillDao;
	private SetuBillItemDao setuBillItemDao;
	private MakeTypeDao makeTypeDao;
	private TallySetDao tallySetDao;
	private QueryDao queryDao;
	private CodeRuleDao codeRuleDao;
	private SerialNumberDao serialNumberDao;
	private IdGenerator idGenerator;
	private SetuBillService setuBillService;
	private DataSource dataSource;

	public String getListForCompView() {
		return this.listForCompView;
	}

	public void setListForCompView(String listForCompView) {
		this.listForCompView = listForCompView;
	}

	public String getListForUnCompView() {
		return this.listForUnCompView;
	}

	public void setListForUnCompView(String listForUnCompView) {
		this.listForUnCompView = listForUnCompView;
	}

	public ModelAndView handleSearchResult(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "SETU_BILL_SEAR")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			String contentType = request.getParameter("content_type");
			QueryParameterBean b = EncSetuBillMACtrHelper.handleSearchResult(
					request, this.dataSource);
			String[] countObjs = new String[]{"sum(b.cost)"};
			QueryResult qr;
			if (contentType != null && contentType.equals("EXCEL")) {
				qr = this.queryDao.doQuery(b.getQParas(), b.getOParas(),
						(String[]) null, b.getShortNameMap(), b.getRetObjs(),
						countObjs);
			} else {
				qr = this.queryDao.doQuery(b.getCurrentPage(), b.getPageSize(),
						b.getQParas(), b.getOParas(), (String[]) null,
						b.getShortNameMap(), b.getRetObjs(), countObjs);
			}

			Object[] objs = qr.getExtCount();
			BigDecimal costTotal = new BigDecimal(0);
			if (objs[0] != null) {
				costTotal = (BigDecimal) objs[0];
			}

			if (contentType != null && contentType.equals("EXCEL")) {
				HashMap mv1 = new HashMap();
				mv1.put("list", qr.getList());
				mv1.put("costTotal", costTotal);
				SetuBillListExcelView ub1 = new SetuBillListExcelView();
				return new ModelAndView(ub1, mv1);
			} else {
				ModelAndView mv = new ModelAndView(this.searchResultView);
				mv.addObject("qr", qr);
				mv.addAllObjects(b.getParameters());
				UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
				mv.addObject("tsList",
						PageHelper.getTallySetList(this.tallySetDao, ub));
				mv.addObject("costTotal", costTotal);
				return mv;
			}
		}
	}

	public ModelAndView handleExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		String idStr = request.getParameter("id_str");
		String flag = request.getParameter("flag");
		boolean examined = false;
		if (flag != null && flag.equals("1")) {
			examined = true;
		}

		String[] arr = idStr.split(";");
		boolean num = false;
		String msg;
		int w;
		byte arg15;
		if (!examined) {
			if (!EncCommonHelper.checkPrivilege(request, "SETU_UN_EXAM")) {
				throw new Exception("Permission deny!");
			}

			try {
				for (w = 0; w < arr.length; ++w) {
					this.setuBillService.txUnExamine(Long.parseLong(arr[w]),
							ub, this.setuBillDao, this.setuBillItemDao,
							this.businessBillItemDao);
				}

				msg = "反审核成功";
			} catch (NotAllowException arg13) {
				msg = arg13.getMessage();
			} catch (CannotAcquireLockException arg14) {
				msg = "事务冲突故障，请重新操作！";
			}

			arg15 = 1;
		} else {
			if (!EncCommonHelper.checkPrivilege(request, "SETU_EXAM")) {
				throw new Exception("Permission deny!");
			}

			try {
				for (w = 0; w < arr.length; ++w) {
					this.setuBillService.txExamine(Long.parseLong(arr[w]), ub,
							this.setuBillDao, this.setuBillItemDao,
							this.businessBillItemDao);
				}

				msg = "审核成功";
			} catch (NotAllowException arg11) {
				msg = arg11.getMessage();
			} catch (CannotAcquireLockException arg12) {
				msg = "事务冲突故障，请重新操作！";
			}

			arg15 = 1;
		}

		mv.addObject("returnValue", String.valueOf(arg15));
		EncCommonHelper.setAlertMessage(request, msg);
		return mv;
	}

	public ModelAndView handleListForExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "SETU_EXAM")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForExamineView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			long managerId = 0L;
			if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
				managerId = ub.getStaffer().getId();
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.setuBillDao.getListCount(searchKey, false,
					Long.parseLong(tsId), managerId, ub, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.setuBillDao.getList(searchKey, false,
					Long.parseLong(tsId), managerId, ub, allowStart,
					"BILL_DATE", startIndex, perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForExamineView);
		String id = request.getParameter("id");
		this.getSetuBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleListForUnExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "SETU_UN_EXAM")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForUnExamineView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			long managerId = 0L;
			if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
				managerId = ub.getStaffer().getId();
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.setuBillDao.getListCount(searchKey, true,
					Long.parseLong(tsId), managerId, ub, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.setuBillDao.getList(searchKey, true,
					Long.parseLong(tsId), managerId, ub, allowStart, "ID_DESC",
					startIndex, perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForUnExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForUnExamineView);
		String id = request.getParameter("id");
		this.getSetuBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleListForCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "SETU_CANC")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForCancelView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			long managerId = 0L;
			if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
				managerId = ub.getStaffer().getId();
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.setuBillDao.getListCount(searchKey,
					Long.parseLong(tsId), managerId, ub, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.setuBillDao.getList(searchKey,
					Long.parseLong(tsId), managerId, ub, allowStart, "",
					startIndex, perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForCancelView);
		String id = request.getParameter("id");
		this.getSetuBill(mv, Long.parseLong(id));
		return mv;
	}

	public ModelAndView handleCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		if (!EncCommonHelper.checkPrivilege(request, "SETU_CANC")) {
			throw new Exception("Permission deny!");
		} else {
			String id = request.getParameter("id");
			String reason = request.getParameter("reason");
			String msg = "作废成功";

			try {
				this.setuBillService.txCancel(Long.parseLong(id), reason, ub,
						this.setuBillDao, this.setuBillItemDao,
						this.businessBillItemDao, this.idGenerator);
			} catch (NotAllowException arg8) {
				msg = arg8.getMessage();
			} catch (CannotAcquireLockException arg9) {
				msg = "事务冲突故障，请重新操作！";
			}

			mv.addObject("returnValue", id);
			EncCommonHelper.setAlertMessage(request, msg);
			return mv;
		}
	}

	private void getSetuBill(ModelAndView mv, long id) throws Exception {
		SetuBill setuBill = (SetuBill) this.setuBillDao.get(SetuBill.class, id);
		SetuBillBean form = new SetuBillBean();
		if (setuBill != null && !setuBill.getEnab().equals("N")) {
			BusinessBill businessBill = (BusinessBill) this.setuBillDao.get(
					BusinessBill.class, setuBill.getBbId());
			if (businessBill == null) {
				throw new Exception("Business bill not found for id:"
						+ setuBill.getBbId());
			} else {
				form.setSetuBill(setuBill);
				List itemList = this.setuBillItemDao.getListBySetuBill(setuBill
						.getId());
				Establishment est = (Establishment) this.setuBillDao.get(
						Establishment.class, businessBill.getClientId());
				if (est != null) {
					form.setClientName(est.getEstName());
				}

				TallySet ts = (TallySet) this.setuBillDao.get(TallySet.class,
						setuBill.getTsId());
				if (ts != null) {
					form.setTsName(ts.getTitle());
				}

				form.setBbCode(businessBill.getBillCode());
				ArrayList arr = new ArrayList();
				List bbItemList = this.businessBillItemDao.getList(businessBill
						.getId());
				List makeTypeList = this.makeTypeDao.getList(false);

				int beginIndex;
				for (beginIndex = 0; beginIndex < itemList.size(); ++beginIndex) {
					SetuBillItemBean itemBean = new SetuBillItemBean();
					SetuBillItem item = (SetuBillItem) itemList.get(beginIndex);
					itemBean.setSetuBillItem(item);

					for (int j = 0; j < bbItemList.size(); ++j) {
						BusinessBillItem bbItem = (BusinessBillItem) bbItemList
								.get(j);
						if (bbItem.getId() == item.getBbItemId()) {
							itemBean.setMakeTypeName(EncCommonHelper
									.getSimpleObjectName(makeTypeList,
											bbItem.getMakeTypeId()));
							itemBean.setProductName(bbItem.getProName());
							itemBean.setSpecification(bbItem.getSpecification());
							itemBean.setFinishedContent(bbItem
									.getFinishedContent());
							itemBean.setMakeRequire(bbItem.getMakeRequire());
							itemBean.setAmountTotal(bbItem.getAmount());
							if (bbItem.getPriceType().equals("AMOUNT")) {
								itemBean.setUnitPrice(bbItem.getUnitPrice());
								itemBean.setUnit(bbItem.getUnit());
							} else if (bbItem.getPriceType().equals("AREA")) {
								itemBean.setUnitPrice(bbItem.getCost().divide(
										bbItem.getAmount(), 4, 4));
								itemBean.setUnit(this.getUnit(makeTypeList,
										bbItem.getMakeTypeId()));
							} else if (bbItem.getPriceType().equals("LENGTH")) {
								itemBean.setUnitPrice(bbItem.getCost().divide(
										bbItem.getAmount(), 4, 4));
								itemBean.setUnit(this.getUnit(makeTypeList,
										bbItem.getMakeTypeId()));
							}
							break;
						}
					}

					arr.add(itemBean);
				}

				form.setItems(arr);
				if (setuBill.getExamImg() != null
						&& !setuBill.getExamImg().equals("")) {
					beginIndex = setuBill.getExamImg().lastIndexOf("/");
					form.setExamImgName(setuBill.getExamImg().substring(
							beginIndex + 1));
				}

				mv.addObject("record", form);
				mv.addObject("est", est);
			}
		} else {
			throw new Exception("Record not found or enabled for id:" + id);
		}
	}

	private String getUnit(List<?> makeTypeList, long makeTypeId) {
		String unit = "";
		if (makeTypeId != 0L) {
			for (int j = 0; j < makeTypeList.size(); ++j) {
				MakeType p = (MakeType) makeTypeList.get(j);
				if (p.getId() == makeTypeId) {
					unit = p.getUnit();
					break;
				}
			}
		}

		return unit;
	}

	public ModelAndView handlePrint(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String contentType = request.getParameter("content_type");
		if (contentType != null && contentType.equals("WORD")) {
			SetuBill arg36 = (SetuBill) this.setuBillDao.get(SetuBill.class,
					Long.parseLong(id));
			BusinessBill busiBill = (BusinessBill) this.setuBillDao.get(
					BusinessBill.class, arg36.getBbId());
			Establishment est = (Establishment) this.setuBillDao.get(
					Establishment.class, busiBill.getClientId());
			response.reset();
			response.setContentType("APPLICATION/vnd.ms-word");
			response.setHeader("Content-Disposition", "attachment;filename=\""
					+ arg36.getBillCode() + ".doc\"");
			response.setHeader("Content-Transfer-Encoding", "binary");
			response.setHeader("Cache-Control", "no-cache");
			response.setHeader("Pragma", "no-cache");
			EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
			String path = this.getServletContext().getRealPath("/");
			Image logo = null;

			try {
				logo = Image.getInstance(path + ent.getLoginImage());
			} catch (Exception arg35) {
				;
			}

			BaseFont bfChinese = BaseFont.createFont("STSongStd-Light",
					"UniGB-UCS2-H", false);
			Font ttlFont = new Font(bfChinese, 14.0F, 1);
			Font headFont = new Font(bfChinese, 10.0F, 1);
			Font font = new Font(bfChinese, 10.0F, 0);
			ServletOutputStream out = response.getOutputStream();
			Document doc = new Document(PageSize.A4, 50.0F, 50.0F, 50.0F, 50.0F);
			RtfWriter2 r = RtfWriter2.getInstance(doc, out);
			r.setMargins(46.0F, 46.0F, 20.0F, 20.0F);
			r.open();
			Table ttlTbl = new Table(2);
			ttlTbl.setAlignment(0);
			ttlTbl.setWidth(100.0F);
			ttlTbl.setBorderWidth(0.0F);
			logo.scaleAbsolute(logo.getWidth() * 100.0F / 133.0F,
					logo.getHeight() * 100.0F / 133.0F);
			float logoWidth = logo.getPlainWidth() * 100.0F
					/ (doc.getPageSize().getWidth() - 46.0F - 46.0F);
			ttlTbl.setWidths(new float[]{logoWidth, 100.0F - logoWidth});
			Cell cell;
			if (logo != null) {
				cell = new Cell(logo);
			} else {
				cell = new Cell();
			}

			cell.setBorderWidth(0.0F);
			cell.setRowspan(2);
			ttlTbl.addCell(cell);
			cell = new Cell(new Paragraph("\n安装单\n", ttlFont));
			cell.setBorderWidth(0.0F);
			cell.setHorizontalAlignment(1);
			cell.setVerticalAlignment(5);
			ttlTbl.addCell(cell);
			cell = new Cell();
			if (ent.getDeliBc().equals("Y")) {
				Barcode128 headTbl = new Barcode128();
				headTbl.setCode(arg36.getBillCode());
				java.awt.Image itemTbl = headTbl.createAwtImage(Color.black,
						Color.white);
				BufferedImage itemList = new BufferedImage(
						itemTbl.getWidth((ImageObserver) null),
						itemTbl.getHeight((ImageObserver) null), 1);
				Graphics2D bbItemList = (Graphics2D) itemList.getGraphics();
				bbItemList.fillRect(0, 0,
						itemTbl.getWidth((ImageObserver) null),
						itemTbl.getHeight((ImageObserver) null));
				bbItemList.drawImage(itemTbl, 0, 0,
						itemTbl.getWidth((ImageObserver) null),
						itemTbl.getHeight((ImageObserver) null), Color.white,
						(ImageObserver) null);
				bbItemList.dispose();
				ByteArrayOutputStream mtList = new ByteArrayOutputStream();
				ImageIO.write(itemList, "PNG", mtList);
				cell.add(Image.getInstance(mtList.toByteArray()));
				mtList.close();
			}

			cell.add(new Paragraph(est.getEstCode() + " NO."
					+ arg36.getBillCode(), font));
			cell.setBorderWidth(0.0F);
			cell.setHorizontalAlignment(2);
			cell.setVerticalAlignment(6);
			ttlTbl.addCell(cell);
			Table arg37 = new Table(3);
			arg37.setWidth(100.0F);
			arg37.setWidths(new float[]{33.0F, 33.0F, 34.0F});
			arg37.setBorderWidth(0.0F);
			Paragraph para = new Paragraph();
			para.add(new Chunk("订货单位：", headFont));
			para.add(new Chunk(est.getEstName(), font));
			cell = new Cell(para);
			cell.setBorderWidth(0.0F);
			arg37.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("联系人：", headFont));
			para.add(new Chunk(arg36.getLm() + " " + arg36.getPhon(), font));
			cell = new Cell(para);
			cell.setBorderWidth(0.0F);
			arg37.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("业务单号：", headFont));
			para.add(new Chunk(busiBill.getBillCode(), font));
			cell = new Cell(para);
			cell.setBorderWidth(0.0F);
			arg37.addCell(cell);
			Table arg38 = new Table(9);
			arg38.setWidth(100.0F);
			arg38.setWidths(new float[]{10.0F, 12.0F, 12.0F, 14.0F, 14.0F,
					10.0F, 10.0F, 8.0F, 10.0F});
			cell = new Cell(new Paragraph("项目类型", headFont));
			cell.setHorizontalAlignment(1);
			arg38.addCell(cell);
			cell = new Cell(new Paragraph("内容", headFont));
			cell.setHorizontalAlignment(1);
			arg38.addCell(cell);
			cell = new Cell(new Paragraph("材质", headFont));
			cell.setHorizontalAlignment(1);
			arg38.addCell(cell);
			cell = new Cell(new Paragraph("规格", headFont));
			cell.setHorizontalAlignment(1);
			arg38.addCell(cell);
			cell = new Cell(new Paragraph("制作要求", headFont));
			cell.setHorizontalAlignment(1);
			arg38.addCell(cell);
			cell = new Cell(new Paragraph("订货数量", headFont));
			cell.setHorizontalAlignment(1);
			arg38.addCell(cell);
			cell = new Cell(new Paragraph("本次安装", headFont));
			cell.setHorizontalAlignment(1);
			arg38.addCell(cell);
			cell = new Cell(new Paragraph("单位", headFont));
			cell.setHorizontalAlignment(1);
			arg38.addCell(cell);
			cell = new Cell(new Paragraph("备注", headFont));
			cell.setHorizontalAlignment(1);
			arg38.addCell(cell);
			List arg39 = this.setuBillItemDao.getListBySetuBill(arg36.getId());
			List arg40 = this.businessBillItemDao.getList(busiBill.getId());
			List arg41 = this.makeTypeDao.getList(false);

			String tmpStr;
			for (int imgTbl = 0; imgTbl < arg39.size(); ++imgTbl) {
				SetuBillItem maxImgWidth = (SetuBillItem) arg39.get(imgTbl);

				for (int extTbl = 0; extTbl < arg40.size(); ++extTbl) {
					BusinessBillItem sf = (BusinessBillItem) arg40.get(extTbl);
					if (sf.getId() == maxImgWidth.getBbItemId()) {
						cell = new Cell(new Paragraph(
								EncCommonHelper.getSimpleObjectName(arg41,
										sf.getMakeTypeId()), font));
						cell.setHorizontalAlignment(1);
						arg38.addCell(cell);
						cell = new Cell(new Paragraph(sf.getFinishedContent(),
								font));
						cell.setHorizontalAlignment(1);
						arg38.addCell(cell);
						cell = new Cell(new Paragraph(sf.getProName(), font));
						cell.setHorizontalAlignment(1);
						arg38.addCell(cell);
						cell = new Cell(new Paragraph(sf.getSpecification(),
								font));
						cell.setHorizontalAlignment(1);
						arg38.addCell(cell);
						cell = new Cell(
								new Paragraph(sf.getMakeRequire(), font));
						cell.setHorizontalAlignment(1);
						arg38.addCell(cell);
						cell = new Cell(
								new Paragraph(
										EncCommonHelper.parseBigDecimal(sf
												.getAmount()), font));
						cell.setHorizontalAlignment(1);
						arg38.addCell(cell);
						cell = new Cell(new Paragraph(
								EncCommonHelper.parseBigDecimal(maxImgWidth
										.getAmount()), font));
						cell.setHorizontalAlignment(1);
						arg38.addCell(cell);
						tmpStr = "";
						if (sf.getPriceType().equals("AMOUNT")) {
							tmpStr = sf.getUnit();
						} else if (sf.getPriceType().equals("AREA")) {
							tmpStr = this.getUnit(arg41, sf.getMakeTypeId());
						} else if (sf.getPriceType().equals("LENGTH")) {
							tmpStr = this.getUnit(arg41, sf.getMakeTypeId());
						}

						cell = new Cell(new Paragraph(tmpStr, font));
						cell.setHorizontalAlignment(1);
						arg38.addCell(cell);
						cell = new Cell(new Paragraph(maxImgWidth.getMark(),
								font));
						cell.setHorizontalAlignment(1);
						arg38.addCell(cell);
						break;
					}
				}
			}

			Table arg42;
			if (arg36.getCompImg() != null && !arg36.getCompImg().equals("")) {
				arg42 = new Table(2);
				arg42.setWidths(new float[]{50.0F, 50.0F});
				cell = new Cell(new Paragraph("小样效果图", headFont));
				cell.setHorizontalAlignment(1);
				arg42.addCell(cell);
				cell = new Cell(new Paragraph("完工后照片", headFont));
				cell.setHorizontalAlignment(1);
				arg42.addCell(cell);
			} else {
				arg42 = new Table(1);
				cell = new Cell(new Paragraph("小样效果图", headFont));
				cell.setHorizontalAlignment(1);
				arg42.addCell(cell);
			}

			arg42.setWidth(100.0F);
			cell = new Cell();
			float arg43 = 200.0F;
			Image arg44;
			float arg45;
			float arg48;
			if (arg36.getExamImg() != null && !arg36.getExamImg().equals("")) {
				arg44 = null;

				try {
					arg44 = Image.getInstance(path + arg36.getExamImg());
				} catch (Exception arg34) {
					;
				}

				if (arg44 != null) {
					arg45 = arg44.getWidth() * 100.0F / 133.0F;
					arg48 = arg44.getHeight() * 100.0F / 133.0F;
					if (arg45 > arg43) {
						arg48 = arg48 * arg43 / arg45;
						arg45 = arg43;
					}

					arg44.scaleAbsolute(arg45, arg48);
					cell.setHorizontalAlignment(1);
					cell.add(arg44);
				}
			}

			arg42.addCell(cell);
			if (arg36.getCompImg() != null && !arg36.getCompImg().equals("")) {
				arg44 = null;

				try {
					arg44 = Image.getInstance(path + arg36.getCompImg());
				} catch (Exception arg33) {
					;
				}

				if (arg44 != null) {
					arg45 = arg44.getWidth() * 100.0F / 133.0F;
					arg48 = arg44.getHeight() * 100.0F / 133.0F;
					if (arg45 > arg43) {
						arg48 = arg48 * arg43 / arg45;
						arg45 = arg43;
					}

					arg44.scaleAbsolute(arg45, arg48);
					cell = new Cell();
					cell.setHorizontalAlignment(1);
					cell.add(arg44);
					arg42.addCell(cell);
				}
			}

			Table arg46 = new Table(2);
			arg46.setWidths(new float[]{50.0F, 50.0F});
			arg46.setWidth(100.0F);
			SimpleDateFormat arg47 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			para = new Paragraph();
			para.add(new Chunk("派单日期：", headFont));
			para.add(new Chunk(arg47.format(arg36.getBillDate()), font));
			cell = new Cell(para);
			arg46.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("应完工日期：", headFont));
			para.add(new Chunk(arg47.format(arg36.getPlanDate()), font));
			cell = new Cell(para);
			arg46.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("项目总金额：", headFont));
			para.add(new Chunk(arg36.getCost().toString(), font));
			cell = new Cell(para);
			arg46.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("余额：", headFont));
			para.add(new Chunk(arg36.getRemaCost().toString(), font));
			cell = new Cell(para);
			arg46.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("安装地址：", headFont));
			para.add(new Chunk(arg36.getAddr(), font));
			cell = new Cell(para);
			cell.setColspan(2);
			arg46.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("安装要求：", headFont));
			para.add(new Chunk(arg36.getRequ(), font));
			cell = new Cell(para);
			cell.setColspan(2);
			arg46.addCell(cell);
			tmpStr = "";
			if (arg36.getNeedCar().equals("Y")) {
				tmpStr = tmpStr + " 需要派车";
			}

			if (arg36.getNeedHigh().equals("Y")) {
				tmpStr = tmpStr + " 高空作业";
			}

			if (arg36.getNeedWeld().equals("Y")) {
				tmpStr = tmpStr + " 焊接作业";
			}

			if (arg36.getNeedStee().equals("Y")) {
				tmpStr = tmpStr + " 不锈钢";
			}

			para = new Paragraph();
			para.add(new Chunk("安装配备：", headFont));
			para.add(new Chunk(tmpStr, font));
			cell = new Cell(para);
			cell.setColspan(2);
			arg46.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("备注：", headFont));
			para.add(new Chunk(arg36.getMark(), font));
			cell = new Cell(para);
			cell.setColspan(2);
			arg46.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("注意事项：\n", headFont));
			cell = new Cell(para);
			cell.setColspan(2);
			arg46.addCell(cell);
			Table footTbl = new Table(3);
			footTbl.setWidths(new float[]{40.0F, 30.0F, 30.0F});
			footTbl.setWidth(100.0F);
			para = new Paragraph();
			para.add(new Chunk("参加安装人员：", headFont));
			para.add(new Chunk(arg36.getSetuNameStr(), font));
			cell = new Cell(para);
			footTbl.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("接单人签字：", headFont));
			cell = new Cell(para);
			footTbl.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("安装负责人签字：", headFont));
			cell = new Cell(para);
			footTbl.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("客户签字：", headFont));
			cell = new Cell(para);
			footTbl.addCell(cell);
			para = new Paragraph();
			para.add(new Chunk("是否满意（请打“√”  满意  基本满意  不满意）", headFont));
			cell = new Cell(para);
			cell.setColspan(2);
			footTbl.addCell(cell);
			cell = new Cell(new Paragraph("\n\n"));
			cell.setColspan(3);
			footTbl.addCell(cell);
			r.add(ttlTbl);
			r.add(arg37);
			r.add(arg38);
			r.add(arg42);
			r.add(arg46);
			r.add(footTbl);
			CodeRule cr = this.codeRuleDao.get("SETU_BILL");
			r.add(new Paragraph(cr.getPrintFoot()));
			r.close();
			out.flush();
			out.close();
			return null;
		} else {
			ModelAndView mv = new ModelAndView(this.printView);
			this.getSetuBill(mv, Long.parseLong(id));
			mv.addObject("codeRule", this.codeRuleDao.get("SETU_BILL"));
			return mv;
		}
	}

	public ModelAndView handleListForComp(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "SETU_COMP")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			String contentType = request.getParameter("content_type");
			QueryParameterBean b = EncSetuBillMACtrHelper.handleListForComp(
					request, this.dataSource);
			QueryResult qr;
			if (contentType != null && contentType.equals("EXCEL")) {
				qr = this.queryDao.doQuery(b.getQParas(), b.getOParas(),
						(String[]) null, b.getShortNameMap(), b.getRetObjs(),
						(String[]) null);
				HashMap mv1 = new HashMap();
				mv1.put("list", qr.getList());
				SetuBillListForCompExcelView ub1 = new SetuBillListForCompExcelView();
				return new ModelAndView(ub1, mv1);
			} else {
				qr = this.queryDao.doQuery(b.getCurrentPage(), b.getPageSize(),
						b.getQParas(), b.getOParas(), (String[]) null,
						b.getShortNameMap(), b.getRetObjs(), (String[]) null);
				ModelAndView mv = new ModelAndView(this.listForCompView);
				mv.addObject("qr", qr);
				mv.addAllObjects(b.getParameters());
				UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
				mv.addObject("tsList",
						PageHelper.getTallySetList(this.tallySetDao, ub));
				return mv;
			}
		}
	}

	public ModelAndView handleListForUnComp(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "SETU_UN_COMP")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			QueryParameterBean b = EncSetuBillMACtrHelper.handleListForUnComp(
					request, this.dataSource);
			QueryResult qr = this.queryDao.doQuery(b.getCurrentPage(),
					b.getPageSize(), b.getQParas(), b.getOParas(),
					(String[]) null, b.getShortNameMap(), b.getRetObjs(),
					(String[]) null);
			ModelAndView mv = new ModelAndView(this.listForUnCompView);
			mv.addObject("qr", qr);
			mv.addAllObjects(b.getParameters());
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			mv.addObject("tsList",
					PageHelper.getTallySetList(this.tallySetDao, ub));
			return mv;
		}
	}

	public ModelAndView handleUnComp(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		String idStr = request.getParameter("id_str");
		String[] arr = idStr.split(";");
		boolean num = false;
		if (!EncCommonHelper.checkPrivilege(request, "SETU_UN_COMP")) {
			throw new Exception("Permission deny!");
		} else {
			String msg;
			try {
				for (int w = 0; w < arr.length; ++w) {
					this.setuBillService.txUnComp(Long.parseLong(arr[w]),
							this.setuBillDao);
				}

				msg = "反完工成功";
			} catch (NotAllowException arg8) {
				msg = arg8.getMessage();
			} catch (CannotAcquireLockException arg9) {
				msg = "事务冲突故障，请重新操作！";
			}

			byte arg10 = 1;
			mv.addObject("returnValue", String.valueOf(arg10));
			EncCommonHelper.setAlertMessage(request, msg);
			return mv;
		}
	}

	public ModelAndView handleAppInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "SETU_COMP")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("bill_code");
				SetuBill json = this.setuBillDao.get(mapper);
				if (json != null) {
					SimpleDateFormat out = new SimpleDateFormat(
							"yyyy-MM-dd HH:mm");
					String estName = "";
					BusinessBill bb = (BusinessBill) this.setuBillDao.get(
							BusinessBill.class, json.getBbId());
					if (bb != null) {
						Establishment est = (Establishment) this.setuBillDao
								.get(Establishment.class, bb.getClientId());
						if (est != null) {
							estName = est.getEstName();
						}
					}

					map.put("billId", Long.valueOf(json.getId()));
					map.put("estName", estName);
					map.put("billCode", json.getBillCode());
					map.put("billDate", out.format(json.getBillDate()));
					map.put("setuNameStr",
							PageHelper.parseNull(json.getSetuNameStr()));
					map.put("setuIdStr",
							PageHelper.parseNull(json.getSetuIdStr()));
					map.put("cost", json.getCost());
					map.put("status", "OK");
					map.put("errMsg", "");
				} else {
					map.put("status", "ERROR");
					map.put("errMsg", "系统不能识别这个条形码：" + mapper);
				}
			} catch (Exception arg11) {
				map.put("status", "ERROR");
				map.put("errMsg", arg11.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper mapper1 = new ObjectMapper();
		String json1 = mapper1.writeValueAsString(map);
		ServletOutputStream out1 = response.getOutputStream();
		out1.write(json1.getBytes("utf-8"));
		out1.flush();
		out1.close();
		return null;
	}

	public ModelAndView handleAppComp(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String status = "";
		String errMsg = "";
		String json;
		if (ub == null) {
			status = "NO_LOGIN";
		} else {
			String map = request.getParameter("id");
			String mapper = request.getParameter("cost");
			json = request.getParameter("setu_name_str");
			String out = request.getParameter("setu_id_str");
			String compImg = request.getParameter("comp_img");
			if (!EncCommonHelper.checkPrivilege(request, "SETU_COMP")) {
				status = "ERROR";
				errMsg = "您还没有此功能的使用权限，请确认返回！";
			} else {
				try {
					this.setuBillService.txComp(Long.parseLong(map),
							new Date(), out, json, new BigDecimal(mapper),
							compImg, ub, this.setuBillDao, this.idGenerator);
					status = "OK";
				} catch (CannotAcquireLockException arg12) {
					status = "ERROR";
					errMsg = "事务冲突故障，请重新操作！";
				} catch (Exception arg13) {
					status = "ERROR";
					errMsg = arg13.getMessage();
				}
			}
		}

		HashMap map1 = new HashMap();
		map1.put("status", status);
		map1.put("errMsg", errMsg);
		ObjectMapper mapper1 = new ObjectMapper();
		json = mapper1.writeValueAsString(map1);
		ServletOutputStream out1 = response.getOutputStream();
		out1.write(json.getBytes("utf-8"));
		out1.flush();
		out1.close();
		return null;
	}

	public SetuBillDao getSetuBillDao() {
		return this.setuBillDao;
	}

	public void setSetuBillDao(SetuBillDao setuBillDao) {
		this.setuBillDao = setuBillDao;
	}

	public QueryDao getQueryDao() {
		return this.queryDao;
	}

	public void setQueryDao(QueryDao queryDao) {
		this.queryDao = queryDao;
	}

	public String getSearchResultView() {
		return this.searchResultView;
	}

	public void setSearchResultView(String searchResultView) {
		this.searchResultView = searchResultView;
	}

	public SetuBillItemDao getSetuBillItemDao() {
		return this.setuBillItemDao;
	}

	public void setSetuBillItemDao(SetuBillItemDao setuBillItemDao) {
		this.setuBillItemDao = setuBillItemDao;
	}

	public String getDialogSuccessView() {
		return this.dialogSuccessView;
	}

	public void setDialogSuccessView(String dialogSuccessView) {
		this.dialogSuccessView = dialogSuccessView;
	}

	public String getInfoForExamineView() {
		return this.infoForExamineView;
	}

	public void setInfoForExamineView(String infoForExamineView) {
		this.infoForExamineView = infoForExamineView;
	}

	public String getInfoForUnExamineView() {
		return this.infoForUnExamineView;
	}

	public void setInfoForUnExamineView(String infoForUnExamineView) {
		this.infoForUnExamineView = infoForUnExamineView;
	}

	public String getListForExamineView() {
		return this.listForExamineView;
	}

	public void setListForExamineView(String listForExamineView) {
		this.listForExamineView = listForExamineView;
	}

	public String getListForUnExamineView() {
		return this.listForUnExamineView;
	}

	public void setListForUnExamineView(String listForUnExamineView) {
		this.listForUnExamineView = listForUnExamineView;
	}

	public String getPrintView() {
		return this.printView;
	}

	public void setPrintView(String printView) {
		this.printView = printView;
	}

	public String getInfoForCancelView() {
		return this.infoForCancelView;
	}

	public void setInfoForCancelView(String infoForCancelView) {
		this.infoForCancelView = infoForCancelView;
	}

	public String getListForCancelView() {
		return this.listForCancelView;
	}

	public void setListForCancelView(String listForCancelView) {
		this.listForCancelView = listForCancelView;
	}

	public SetuBillService getSetuBillService() {
		return this.setuBillService;
	}

	public void setSetuBillService(SetuBillService setuBillService) {
		this.setuBillService = setuBillService;
	}

	public DataSource getDataSource() {
		return this.dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public TallySetDao getTallySetDao() {
		return this.tallySetDao;
	}

	public void setTallySetDao(TallySetDao tallySetDao) {
		this.tallySetDao = tallySetDao;
	}

	public BusinessBillItemDao getBusinessBillItemDao() {
		return this.businessBillItemDao;
	}

	public void setBusinessBillItemDao(BusinessBillItemDao businessBillItemDao) {
		this.businessBillItemDao = businessBillItemDao;
	}

	public MakeTypeDao getMakeTypeDao() {
		return this.makeTypeDao;
	}

	public void setMakeTypeDao(MakeTypeDao makeTypeDao) {
		this.makeTypeDao = makeTypeDao;
	}

	public CodeRuleDao getCodeRuleDao() {
		return this.codeRuleDao;
	}

	public void setCodeRuleDao(CodeRuleDao codeRuleDao) {
		this.codeRuleDao = codeRuleDao;
	}

	public IdGenerator getIdGenerator() {
		return this.idGenerator;
	}

	public void setIdGenerator(IdGenerator idGenerator) {
		this.idGenerator = idGenerator;
	}

	public SerialNumberDao getSerialNumberDao() {
		return this.serialNumberDao;
	}

	public void setSerialNumberDao(SerialNumberDao serialNumberDao) {
		this.serialNumberDao = serialNumberDao;
	}
}